package io.adrainty.bolee.framework.commons.basic;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * BaseEntity
 *
 * @author adrainty
 * @version v1.0.0
 * @since 2025/4/16 下午3:48
 */

@Data
@SuppressWarnings("unused")
public class BaseEntity implements Serializable {

    @Serial
    private static final long serialVersionUID = 5096474201673262190L;

    @Schema(description = "主键ID")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long id;

    @JsonProperty("createTime")
    @Schema(description = "创建时间")
    private LocalDateTime createdTime;

    @JsonProperty("updateTime")
    @Schema(description = "修改时间")
    private LocalDateTime modifiedTime;

    @JsonProperty("createBy")
    @Schema(description = "创建用户")
    private String createdBy;

    @JsonProperty("updateBy")
    @Schema(description = "修改用户")
    private String modifiedBy;

    public void setBaseEntity(BaseBO baseBO) {
        this.id = baseBO.getId();
        this.createdTime = baseBO.getCreatedTime();
        this.modifiedTime = baseBO.getModifiedTime();
        if (baseBO.getCreatedBy() != null) {
            this.createdBy = String.valueOf(baseBO.getCreatedBy());
        }
        if (baseBO.getModifiedBy() != null) {
            this.modifiedBy = String.valueOf(baseBO.getModifiedBy());
        }
    }

}
